import request from "../request";

export const login = (data) => {
    return request({
        url: "/login",
        method: "post",
        data
    })
}

// 获取openId
export const fetchOpenId = () => {
    return new Promise((resolve, reject) => {
      uni.login({
        provider: 'weixin',
        success: res => {
          request
            .get({ url: '/user/auth/getUserOpenId', data: { code: res.code } })
            .then(res => {
              if (res.code === 0) {
                resolve(res.data)
              } else {
                reject(new Error('获取openId失败'))
              }
            })
            .catch(err => {
              reject(err)
            })
        },
        fail: err => reject(err)
      })
    })
  }


  /**
 * 快速登录
 * @param {*} data
 * @returns
 */
export const quickLogin = data => {
    return request.post({
      url: '/user/auth/quickLogin',
      data,
      flag: true
    })
  }
  